{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "python_basic.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/yejianfeng2014/python_basic/blob/master/python_basic.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WUieDElWMRC2",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "a5ab4ec1-ff09-4088-8165-458ee1dd833e"
      },
      "source": [
        "print(1)"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "1\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "V8qfw61qMV2V",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def find_max(x,y):\n",
        "    '''\n",
        "    获取两个数值之间较大数的函数。\n",
        "    my_max(x, y)\n",
        "        返回x、y两个参数之间较大的那个\n",
        "    '''\n",
        "    z =x  if x>y   else y\n",
        "    return z\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UWEDJwxuMuWj",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "def say_hi(name):\n",
        "    print(\"___正在执行sayhi 函数\")\n",
        "    print(name + \"你好\")\n",
        "    \n",
        "    "
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "J12njQmMM93T",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "a = 9\n",
        "b = 10\n"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "JIKcXUNJNAzD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "c = find_max(a,b)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "UtGfKPK_NFJD",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "a09a633e-b614-4261-edcf-b8d8cc40db9a"
      },
      "source": [
        "print(c)"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "10\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WFwXvGEUNGIT",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 50
        },
        "outputId": "b6196f91-812d-4616-9ef8-019b1ef21c1f"
      },
      "source": [
        "say_hi(\"lishi\")"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "___正在执行sayhi 函数\n",
            "lishi你好\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-mJwwWD1NO2E",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 134
        },
        "outputId": "736e08b4-e9bf-445c-987c-7ff656a90276"
      },
      "source": [
        "help(find_max)"
      ],
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Help on function find_max in module __main__:\n",
            "\n",
            "find_max(x, y)\n",
            "    获取两个数值之间较大数的函数。\n",
            "    my_max(x, y)\n",
            "        返回x、y两个参数之间较大的那个\n",
            "\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Vji9YjgKNhIz",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "class Person:\n",
        "    hair = \"black\"\n",
        "    def __init__(self,name=\"chail\",age = 9):\n",
        "        # 增加两个实例变量\n",
        "        self.name = name\n",
        "        self.age = age\n",
        "        \n",
        "        \n",
        "    def sayhi(self,content):\n",
        "        print(content)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xe96G6KjOpYD",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "p = Person()"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_e982dbFO7eS",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "9266b2c9-8672-4d44-826e-f967933a6e21"
      },
      "source": [
        "p.name"
      ],
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'chail'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MGD0ecS6Ptsk",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "58673659-00df-4d02-cec8-de5b862e071e"
      },
      "source": [
        "p.age"
      ],
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "9"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TdRo451qPuiz",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 165
        },
        "outputId": "53084131-4a1b-4bf5-c086-6c921a95df33"
      },
      "source": [
        "p.hari"
      ],
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "error",
          "ename": "AttributeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-23-d18002224240>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhari\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
            "\u001b[0;31mAttributeError\u001b[0m: 'Person' object has no attribute 'hari'"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "xlnh-r0KPwSS",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "42034819-5c15-4fcc-ac9e-833e3a3721af"
      },
      "source": [
        "p.hair"
      ],
      "execution_count": 24,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'black'"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "pREpHE7gPzVy",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "2c2abb42-8a99-4c12-dafc-336e23031b44"
      },
      "source": [
        "p.sayhi(\"sfdf\")"
      ],
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "sfdf\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "n0JAQsSkRhdF",
        "colab_type": "text"
      },
      "source": [
        "继承的时候，优先从第一个方法向后查找，第一个找到就部向后找了"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "Xid3_elKP4XB",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 34
        },
        "outputId": "fb84b821-0db0-465a-a205-f778fb6e86f6"
      },
      "source": [
        "class Item:\n",
        "    def info (self):\n",
        "        print(\"Item中方法:\", '这是一个商品')\n",
        "class Product:\n",
        "    def info (self):\n",
        "        print(\"Product中方法:\", '这是一个工业产品')\n",
        "#class Mouse(Item, Product): # ①\n",
        "class Mouse(Product, Item): # ①\n",
        "    pass\n",
        "m = Mouse()\n",
        "m.info()"
      ],
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Product中方法: 这是一个工业产品\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kqTJEfAJRaYA",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}